package org.musicguardian.core.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;

public class Artist implements java.io.Serializable, Comparable<Artist>{
	private String name;
	private TreeSet<Album> albums = new TreeSet<Album>();

	public Artist() {
		super();
	}

	public Artist(String name) {
		super();
		this.name = name;
	}

	public String getName() {
		return name;
	}
	
	public TreeSet<Album> getAlbums() {
		return albums;
	}

	public Artist addAlbum(Album album) {
		albums.add(album);
		return this;
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Artist other = (Artist) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	public int compareTo(Artist artist) {
		return getName().compareTo(artist.getName());
	}

	@Override
	public String toString() {
		String string = "[Artist] "+name;
		for (Iterator<Album> iter = albums.iterator(); iter.hasNext();) {
			Album album = iter.next();
			string+="\n\t"+album.toString();
		}
		return string;
	}

}
